import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/widgets/common/tag_widget.dart';
import 'package:finance_app/src/widgets/select/mixin/radio_mixin.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class ContactsTagItem extends StatelessWidget with RadioMixin {
  final VoidCallback onTap;
  final String title;
  final List<String> tags;
  final bool isSelectMode;
  final bool isOverdue;
  final bool isSelect;
  final bool isCheckStar;
  final bool isLastItem;
  final bool hasCreditBalance;
  final VoidCallback onClickStar;

  const ContactsTagItem(
      {Key key,
      this.isSelectMode,
      this.isOverdue,
      this.onTap,
      this.title,
      this.isSelect = false,
      this.tags,
      this.isCheckStar,
      this.isLastItem = false,
      this.hasCreditBalance = false,
      this.onClickStar})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PressedOpacityButton(
      onPressed: onTap,
      color: isSelect ? aceLightBlue : Colors.white,
      padding: EdgeInsets.symmetric(
        horizontal: getDp(18),
        vertical: getDp(24),
      ),
      border: isLastItem
          ? null
          : Border(
              bottom: BorderSide(
              color: aceGrayColor,
              width: getDp(0.5),
            )),
      child: Row(
        children: [
          if (isSelectMode == true)
            buildSelectWidget
          else
            PressedOpacityButton(
              onPressed: onClickStar,
              child: SvgPicture.asset(
                isCheckStar
                    ? A.assetsImagesDashboardSelectStar
                    : A.assetsImagesDashboardUnselectStar,
                width: getDp(26),
                height: getDp(26),
                fit: BoxFit.contain,
              ),
            ),
          SizedBox(
            width: getDp(15),
          ),
          Expanded(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: TextStyle(
                    color: aceBlackColor,
                    fontSize: getSp(16),
                    fontWeight: FontWeight.w700,
                    height: 14 / 16,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 8.0),
                  child: Flex(
                    direction: Axis.horizontal,
                    children: [
                      if (isOverdue == true)
                        RedTagWidget(
                          content: 'Overdue',
                        ),
                      if (hasCreditBalance == true)
                        Padding(
                          padding: const EdgeInsets.only(left: 8.0),
                          child: BlueTagWidget(
                            content: 'Credit Available',
                          ),
                        ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          if (tags != null)
            ...tags
                .map((e) => Container(
                      margin: EdgeInsets.symmetric(horizontal: getDp(5)),
                      width: getDp(24),
                      height: getDp(24),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: aceGrayColor,
                        shape: BoxShape.circle,
                      ),
                      child: Text(
                        e,
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: getSp(14),
                          fontWeight: FontWeight.w700,
                          height: 1,
                        ),
                      ),
                    ))
                .toList()
        ],
      ),
    );
  }
}
